//
//  AppDelegate.swift
//  ParkManage
//
//  Created by cf on 2020/9/16.
//  Copyright © 2020 diligrp. All rights reserved.
//

import UIKit
import IQKeyboardManagerSwift

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        
        IQKeyboardManager.shared.enable = true
        IQKeyboardManager.shared.toolbarDoneBarButtonItemText = "完成"
        
        NavigationMap.initRouter()
        
        //注册极光推送
        registerJPush(launchOptions: launchOptions)
        //友盟
        registerUM()
        return true
    }
        
    func registerJPush(launchOptions: [UIApplication.LaunchOptionsKey: Any]?) {
        //注册极光推送
        let entity = JPUSHRegisterEntity()
        entity.types = 1 << 0 | 1 << 1 | 1 << 2
        JPUSHService.register(forRemoteNotificationConfig: entity, delegate: self)
        //需要IDFA 功能，定向投放广告功能
        //let advertisingId = ASIdentifierManager.shared().advertisingIdentifier.uuidString
        //通知类型（这里将声音、消息、提醒角标都给加上）
//        let userSettings = UIUserNotificationSettings(types: [.alert, .badge, .sound],
//                                                      categories: nil)
//        if ((UIDevice.current.systemVersion as NSString).floatValue >= 8.0) {
//            //可以添加自定义categories
//            JPUSHService.register(forRemoteNotificationTypes: userSettings.types.rawValue,
//                                  categories: nil)
//        }
//        else {
//            //categories 必须为nil
//            JPUSHService.register(forRemoteNotificationTypes: userSettings.types.rawValue,
//                                  categories: nil)
//    }
      
    //监听自定义消息的接收
    //let defaultCenter =  NotificationCenter.default
    //defaultCenter.addObserver(self, selector: #selector(networkDidReceiveMessage(notification:)),
    //                          name:Notification.Name.jpfNetworkDidReceiveMessage, object: nil)
      
    JPUSHService.setup(withOption: launchOptions,
                       appKey: "1793b9b0d1a4d5d5a6c2558d",
                       channel: "App Store",
                       apsForProduction: false,
                       advertisingIdentifier: nil)
    }
    
    func registerUM() {
        
        //UMConfigure.initWithAppkey("appkey", channel: "App Store")
    }
    
    // MARK: UISceneSession Lifecycle
    func application(
        _ application: UIApplication,
        configurationForConnecting connectingSceneSession: UISceneSession,
        options: UIScene.ConnectionOptions) -> UISceneConfiguration {
        return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
    }

    func application(
        _ application: UIApplication,
        didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {

    }
}
